var e, t = require("../../@babel/runtime/helpers/interopRequireDefault"), a = t(require("../../@babel/runtime/regenerator")), n = t(require("../../@babel/runtime/helpers/asyncToGenerator")), r = t(require("../../@babel/runtime/helpers/slicedToArray")), i = require("../../1D8980678A52ABCF7BEFE860FD67FE64.js"), s = require("../../E52ED4948A52ABCF8348BC934D77FE64.js"), o = require("../../3F2EFC058A52ABCF59489402DCA7FE64.js"), c = getApp();

Page({
    data: {
        questionCategory: "",
        douyin: i.IMGPATH + "but_douyin.png",
        bg_answer: i.IMGPATH + "bg_answer.png",
        im_answer: i.IMGPATH + "im_answer.png",
        icons: {
            icon05: i.IMGPATH + "ic_hot.png",
            icon07: i.IMGPATH + "xingxing.png",
            icon08: i.IMGPATH + "xingxing02.png",
            play: i.IMGPATH + "play.png",
            back: i.IMGPATH + "back.png"
        },
        list: [],
        result: {},
        topDistance: 0,
        backHeight: 0,
        backWidth: 0,
        leftDistance: 0,
        answerImg: "",
        ans: ""
    },
    onLoad: function() {
        var e = this, t = c.globalData.headerBtnPosi, a = c.globalData.winWidth, n = t.top, r = a - t.right, i = t.height, s = 2 * i, o = this.data, u = o.bg_answer, l = o.im_answer, g = Math.ceil(2 * Math.random()), d = 'background-image: url("'.concat(1 == g ? u : l, '")');
        this.setData({
            topDistance: n,
            leftDistance: r,
            answerImg: d,
            ans: g,
            backWidth: s,
            backHeight: i
        }, function() {
            e.setResult();
        });
    },
    setResult: function() {
        var e = this, t = wx.getStorageSync("questionAnswer"), a = t.questionCategory, n = t.answerList, i = t.answerResult, s = t.crossHeadList, o = t.answerType, c = t.title, u = {};
        if (i && n.forEach(function(e) {
            e.answerSeq == i && ((u = e).title = c);
        }), "STAR" == o) {
            var l = i && u.answerContent.split("/"), g = l[1] - l[0], d = parseInt(l[0]);
            u.x1 = new Array(g).fill(1), u.x2 = new Array(d).fill(1);
        } else if ("RANGE" == o) {
            var p = 0;
            s.forEach(function(e) {
                p += e.score;
            });
            for (var h = 0; h < n.length; h++) {
                var f = n[h], w = f.answerContent.split("-"), b = (0, r.default)(w, 2), y = b[0], m = b[1];
                if (p >= y && p <= m) {
                    (u = f).scores = p;
                    break;
                }
            }
        }
        u.answerType = o, this.setData({
            id: t.id,
            result: u,
            questionCategory: a
        }, function() {
            e.fetchData();
        });
    },
    fetchData: (e = (0, n.default)(a.default.mark(function e() {
        var t, n, r, i;
        return a.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return t = this.data, n = t.questionCategory, t.list, e.next = 3, (0, s.ajax)({
                    url: "/api/testQuestion/getPager",
                    data: {
                        keyWord: "",
                        pageSize: 5,
                        pageNumber: 1,
                        questionCategory: n
                    }
                });

              case 3:
                (r = e.sent).code || ((i = r.data.data).length && i.forEach(function(e) {
                    e.reads = (0, o.getRandomNumberByRange)(1e3, 1e5);
                }), this.setData({
                    list: i
                }));

              case 5:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function() {
        return e.apply(this, arguments);
    }),
    onShareAppMessage: function(e) {
        var t = wx.getStorageSync("questionAnswer"), a = t.id;
        return {
            title: t.title,
            imageUrl: t.coverImgUrl,
            path: "".concat("/pages/detail/index", "?id=").concat(a)
        };
    },
    jumpDetail: function(e) {
        var t = e.currentTarget.dataset.id;
        if (!t) throw new Error("detail id 缺失");
        c.openPageMore(), wx.redirectTo({
            url: "/pages/detail/index?id=" + t
        });
    },
    backHandle: function() {
        wx.navigateBack({
            delta: 1
        });
    }
});